﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ComparativeSheet
{
    public partial class BadForm : Form
    {
        public BadForm()
        {
            InitializeComponent();
        }

        private void BadForm_Load(object sender, EventArgs e)
        {
            ComboBox cb = cbDepartments.ComboBox;            
            DataSets.CSDataTableAdapters.DepartmentsTableAdapter dAdapter = new ComparativeSheet.DataSets.CSDataTableAdapters.DepartmentsTableAdapter();
            DataSets.CSData.DepartmentsDataTable depts = dAdapter.GetData();
            cb.ValueMember = "Id";
            cb.DisplayMember = "Name";
            cb.DataSource = depts;
        }

        private void cbDepartments_SelectedIndexChanged(object sender, EventArgs e)
        {
            Int32 dId = (Int32)cbDepartments.ComboBox.SelectedValue;
            badDocumentsTableAdapter.Fill(cSData.BadDocuments, dId);
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
                return;
            dataGridView1.Rows[e.RowIndex].Selected = true;
            DataRowView drv = dataGridView1.Rows[e.RowIndex].DataBoundItem as DataRowView;
            if (drv == null)
                return;
            DataSets.CSData.BadDocumentsRow bdr = drv.Row as DataSets.CSData.BadDocumentsRow;
            if (bdr == null)
                return;
            Int32? inDoc = null;
            Int32? outDoc = null;
            if (!bdr.Isid2Null())
                outDoc = bdr.id2;
            inDoc = bdr.id1;
            CompareLists cl = new CompareLists(outDoc, inDoc);
            cl.ShowDialog();
        }

              
    }
}